package com.yejiarong.weather.agent.controller;

import com.yejiarong.weather.agent.service.IWeatherDataService;
import com.yejiarong.common.tools.HttpResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YeJR
 */
@RestController
@RequestMapping(value = "/weatherData")
public class WeatherDataController {

    private final IWeatherDataService weatherDataService;

    public WeatherDataController(IWeatherDataService weatherDataService) {
        this.weatherDataService = weatherDataService;
    }


    /**
     * 收集天气数据
     */
    @GetMapping(value = "/gather")
    public HttpResult<Void> gatherWeatherData() {
        weatherDataService.gatherWeatherData();
        return HttpResult.success();
    }

    /**
     * 收集某个城市的天气
     * @param city 城市
     */
    @GetMapping(value = "/gather/{city}")
    public HttpResult<Void> gatherWeatherData(@PathVariable(value = "city") String city) {
        weatherDataService.gatherWeatherData(city);
        return HttpResult.success();
    }
}
